package priv.bestbeat.reportcenter.core.mq.rocket;

import lombok.NoArgsConstructor;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import priv.bestbeat.reportcenter.core.monitor.Observable;
import priv.bestbeat.reportcenter.core.mq.MessageProxy;
import priv.bestbeat.reportcenter.core.mq.NoMonitorMessageProxy;

import javax.annotation.Resource;

/**
 * @author 张渠钦
 * @date 2022/4/24 17:16
 */
@NoArgsConstructor
public class SpringRocketMQCommonProxy extends NoMonitorMessageProxy<RocketMessage> {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    public SpringRocketMQCommonProxy(RocketMQTemplate rocketMQTemplate) {
        this.rocketMQTemplate = rocketMQTemplate;
    }

    @Override
    public RocketMessage send(RocketMessage message) throws Exception {
        rocketMQTemplate.send(message.getTopic() + ":" + message.getTags(), message);
        message.sendDone();

        return message;
    }

}
